
package com.timber.util;

import java.awt.*;
import java.awt.datatransfer.*;
import javax.swing.JTextField;


public class SelectTextOnFocusTextField extends JTextField
{

  public SelectTextOnFocusTextField()
  {
    super();
    String val = Global.getAppComponentValue( "SELECT_SEC_ONFOCUS" );
    if( val != null && val.trim().toUpperCase().startsWith( "Y" ) )
      addFocusListener( new SelectTextFocusHandler() );
  }

  private Clipboard clipB = Toolkit.getDefaultToolkit().getSystemClipboard();


  public void paste()
  {
    String str;

    Transferable contents = clipB.getContents( this );
    if( contents == null )
      return;

    try
    {
      str = ( String )( contents.getTransferData( DataFlavor.stringFlavor ) );

      String str1 = str.trim().replace( '\t', ',' );
      String str2 = str1.replace( '\n', ',' );

      replaceSelection( str2 );

    }
    catch( Exception e )
    {
      getToolkit().beep();
    }
  }
}
